package com.game.framwork.gamesupport;

import com.game_ltdd.GameGame;

public class Camera {
	private float cameraX;
	private float cameraY;
	private int mapWidth;
	private int mapHeight;

	public Camera(int width, int height) {
		mapWidth = width;
		mapHeight = height;
		cameraX = 0;
		cameraY = 0;
	}

	public void setViewPort(int cameraPosX, int cameraPosY) {
		int posPlayerX = cameraPosX;
		int posPlayerY = cameraPosY;
		cameraX = posPlayerX - GameGame.getGame().getDeviceWidth() / 2;
		cameraY = posPlayerY - GameGame.getGame().getDeviceHeight() / 2;
		if (cameraY < 0) {
			cameraY = 0;
		} else if (cameraY + GameGame.getGame().getDeviceHeight() >= mapHeight) {
			cameraY = mapHeight - GameGame.getGame().getDeviceHeight();
		}
		if (cameraX < 0) {
			cameraX = 0;
		} else if (cameraX + GameGame.getGame().getDeviceWidth() >= mapWidth) {
			cameraX = mapWidth - GameGame.getGame().getDeviceWidth();
		}
		cameraX = -cameraX;
		cameraY = -cameraY;
	}

	public int getCameraX() {
		return (int) cameraX;
	}

	public int getCameraY() {
		return (int) cameraY;
	}

}
